﻿<UserControl x:Class="SQLServerCompanion.Controls.DBLogon"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
            xmlns:ctl="clr-namespace:SQLServerCompanion.Controls" 
            xmlns:pw="clr-namespace:SQLServerCompanion.HelperClasses"
            xmlns:TypeConverters="clr-namespace:SQLServerCompanion" 
            xmlns:sys="clr-namespace:System;assembly=mscorlib" 
            xmlns:smo="clr-namespace:Microsoft.SqlServer.Management.Common;assembly=Microsoft.SqlServer.ConnectionInfo"  
            Loaded="UserControl_Loaded"            
            mc:Ignorable="d" 
            d:DesignHeight="300" d:DesignWidth="400">

    <UserControl.Resources>
        <TypeConverters:BoolToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="odp">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="smo:NetworkProtocol"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
    </UserControl.Resources>

    <Grid x:Name="root" Margin="5">
        <Border CornerRadius="10" BorderThickness="5" Margin="10" BorderBrush="Black" >
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF8E8C5E"/>
                    <GradientStop Color="White" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            <Grid x:Name="main" Margin="20" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="50" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <!--Grid row 0 -->
                <TextBlock Text="Server Name / IP " Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" />
                <TextBox x:Name="txtServerName" Text="{Binding DBServerName}" Grid.Row="0" Grid.Column="1" MinWidth="200"/>

                <!--Grid row 1 -->
                <TextBlock Text="Use Windows Authentication" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center"/>
                <CheckBox IsChecked="{Binding UseSQLIntegratedAuthentication}" Grid.Row="1" Grid.Column="1" Margin="5,0,5,0" VerticalAlignment="Center"/>

                <!--Grid row 2 -->
                <TextBlock Text="Network Protocol" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center"/>
                <ComboBox Name="cboNetworkProtocol" Grid.Row="2" Grid.Column="1" ItemsSource="{Binding Source={StaticResource odp}}" SelectedItem="{Binding Path=SelectedNetworkProtocol}" />

                <!--Grid row 3 -->
                <TextBlock Text="Username" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center"/>
                <TextBox Text="{Binding Username}" Grid.Row="3" Grid.Column="1" MinWidth="200"/>

                <!--Grid row 4 -->
                <TextBlock Text="Password" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center"/>
                <PasswordBox Grid.Row="4" Grid.Column="1" pw:PasswordHelper.Attach="True" pw:PasswordHelper.Password="{Binding Path=Password, Mode=TwoWay}" MinWidth="200"/>

                <!--Grid row 5 -->
                <ProgressBar Grid.Row="5" Grid.ColumnSpan="2" Height="34" HorizontalAlignment="Center" Margin="10,30,0,0"  
                             Name="ProgressBar1" VerticalAlignment="Top" Width="299" 
                             Orientation="Horizontal" IsIndeterminate="True"                              
                             Foreground="Green"                          
                             Visibility="{Binding Path=IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}"
                             />

                <!--Grid row 6 -->
                <StackPanel Grid.Row="6" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="10,50,10,10">
                    <Button  Command="{Binding DoLogonCommand}" Margin="5" Padding="2" IsDefault="True" IsEnabled="{Binding Path=ShowServerConnectionPopup}"
                        HorizontalAlignment="Center"  Style="{DynamicResource NormalButtonStyle}">Connect</Button>

                    <!--<Button  Command="{Binding DoDisconnectDBCommand}" Margin="5" Padding="2" 
                        HorizontalAlignment="Center"  Style="{DynamicResource NormalButtonStyle}">Disconnect</Button>-->

                    <Button Command="{Binding DoCloseLogonPopupCommand}" Margin="5" Padding="2"
                        HorizontalAlignment="Center" Style="{DynamicResource NormalButtonStyle}">Close</Button>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</UserControl>
